package com.yjyw.tiexie.fragment.second;

import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.ImageView;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;

import com.luck.picture.lib.photoview.OnPhotoTapListener;
import com.luck.picture.lib.photoview.PhotoView;
import com.yjyw.tiexie.R;
import com.yjyw.tiexie.util.ImageLoadUtil;

public class BigImageBannerFragment extends Fragment {

    private int position;

    public BigImageBannerFragment(int position) {
        this.position = position;
    }

    public static final String IMG_URL = "imgUrl";

    PhotoView mIvPic;

    private LayoutInflater mInflater;
    private Button take_frends;
    private Button take_pic;
    private Button btn_cancel;
    private int mimgUrl ;

    @Nullable
    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        View view = LayoutInflater.from(getActivity()).inflate(R.layout.fragment_big_image, null);
        mIvPic = view.findViewById(R.id.pv_pic);
        initListener();
        loadData();
        return view;
    }


    public void initListener() {
        mIvPic.setOnPhotoTapListener(new OnPhotoTapListener() {
            @Override
            public void onPhotoTap(ImageView view, float x, float y) {
                if (getActivity() != null) {
//                    getActivity().finish();
                    onItemCLick.clickPosition(position);
                }
            }
        });
    }

    protected void loadData() {

        int imgUrl = getArguments().getInt(IMG_URL);
        mimgUrl = imgUrl;
        ImageLoadUtil.showImgWithDefaultBanner(mIvPic, mimgUrl);
    }

    private OnItemClick onItemCLick;

    public void setOnItemCLick(OnItemClick onItemCLick) {
        this.onItemCLick = onItemCLick;
    }

    public interface OnItemClick {
        void clickPosition(int position);
    }


}
